package com.freesun.shop.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.freesun.shop.service.SysLogService;
import com.freesun.shop.entity.SysLog;
import com.freesun.shop.mapper.SysLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 系统日志 服务实现类
 * </p>
 *
 * @author zf
 * @since 2019-11-13
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    private static Logger logger = LoggerFactory.getLogger(SysLogServiceImpl.class);

    @Override
    public IPage<SysLog> findByPage(SysLog sysLog, Page<SysLog> page) {
        logger.info("分页查询日志记录,当前页{},每页显示{}",page.getCurrent(),page.getSize());
        IPage<SysLog> iPage = this.baseMapper.selectPage(page, new LambdaQueryWrapper<SysLog>()
                .like(StringUtils.hasText(sysLog.getUsername())
                        , SysLog::getUsername, sysLog.getUsername())
                .and(StringUtils.hasText(sysLog.getOperation()), i->
                    i.like(SysLog::getOperation,sysLog.getOperation())
                )
        );

        return iPage;
    }
}
